unit LW_ImageIO;

{$mode objfpc}{$H+}

interface

uses
  LW_Monitor;

const
  LWIMAGELOADER_CLASS	 = 'ImageLoader';
  LWIMAGELOADER_VERSION  = 3            ;

  LWIMAGESAVER_CLASS	 = 'ImageSaver' ;
  LWIMAGESAVER_VERSION   = 3            ;

  {
    Result Value

    The result value indicates the status of the loader or saver upon
    completion.  If the load or save was sucessful, the value should be
    IPSTAT_OK.  If a loader fails to recognize a file as something it can load
    it should set the result to IPSTAT_NOREC.  If the server could not open
    the file it should return IPSTAT_BADFILE.  Any other error is just a
    generic failure of the loader or saver and so should set the result to
    IPSTAT_FAILED.  Other failure modes might be possible if required
    in the future.
  }

  IPSTAT_OK	 =  0 ;
  IPSTAT_NOREC	 =  1 ;
  IPSTAT_BADFILE =  2 ;
  IPSTAT_ABORT	 =  3 ;
  IPSTAT_FAILED	 = 99 ;

  { Flags to be passed to 'setSize' and 'sendData' callbacks. }
  IMGF_REVERSE   = 1 shl 0 ;

  { TODO 1 -oJameel  -cMacro conversion : Jameel convert this macros, I know you love them ;) }

  { There are also some protocol macros defined
   to get the whole calling interface right. }

  //#define LWIP_SETSIZE(p,w,h)     (*(p)->setSize) ((p)->priv_data,w,h)
  //#define LWIP_SETPARAM(p,t,c)    (*(p)->setParam) ((p)->priv_data,t,c)
  //#define LWIP_ASPECT( p, a )     {                                                \
  //                                    char string [ 256 ];                         \
  //                                    sprintf( string, "%g", a );                  \
  //                                    LWIP_SETPARAM( p, LWIMPAR_ASPECT, string );  \
  //                                }
  //#define LWIP_NUMCOLORS( p, n )  {                                                \
  //                                    char string [ 256 ];                         \
  //                                    sprintf( string, "%d", n );                  \
  //                                    LWIP_SETPARAM( p, LWIMPAR_NUMCOLS, string ); \
  //                                }
  //#define LWIP_SENDLINE(p,ln,d)   (*(p)->sendLine) ((p)->priv_data,ln,d)
  //#define LWIP_SETMAP(p,i,val)    (*(p)->setMap) ((p)->priv_data,i,val)
  //#define LWIP_DONE(p,err)        (*(p)->done) ((p)->priv_data,err)

  {
    Compatibility macros.

    These types are obsolete, but are included to make it easier to convert
    to the new image format.  The IMG_* value have been replaced with the
    LWImageType type codes, although the values of 0, 1 and 2 map to equivalent
    types.  The ImageValue type is gone completely, and a Pixel* structure
    type should be used, or an explicit reference to unsigned char.
 }

  IMG_RGB24	 = 0 ;
  IMG_GREY8	 = 1 ;
  IMG_INDEX8	 = 2 ;


type
  { Image Pixel Datatypes }
  TLWImageType = ( LWIMTYP_RGB24    := 0 ,
                   LWIMTYP_GREY8         ,
                   LWIMTYP_INDEX8        ,
                   LWIMTYP_GREYFP        ,
                   LWIMTYP_RGBFP         ,
                   LWIMTYP_RGBA32        ,
                   LWIMTYP_RGBAFP        ,
                   LWIMTYP_SPECIAL       ,
                   LWIMTYP_GREYDBL       ,
                   LWIMTYP_RGBDBL        ,
                   LWIMTYP_RGBADBL       );

  { Image Pixel Structures }
  PLWPixel = Pointer;

  PLWPixelRGB24 = ^TLWPixelRGB24;
  TLWPixelRGB24  = record
    R , G , B : PByte;
  end;

  PLWPixelRGBFP = ^TLWPixelRGBFP;
  TLWPixelRGBFP  = record
    R , G , B : Single;
  end;

  PLWPixelRGBDBL = ^TLWPixelRGBDBL;
  TLWPixelRGBDBL = record
    R , G , B : Double;
  end;

  PLWPixelRGBA = ^TLWPixelRGBA;
  TLWPixelRGBA   = record
    R , G , B , A : PByte;
  end;

  PLWPixelRGBAFP = ^TLWPixelRGBAFP;
  TLWPixelRGBAFP  = record
    R , G , B, A : Single;
  end;

  PLWPixelRGBADBL = ^TLWPixelRGBADBL;
  TLWPixelRGBADBL = record
    R , G , B, A : Double;
  end;

  { Image Buffer Protocol with parameter tags }

  TLWImageParam = (
    LWIMPAR_ASPECT := 1           , { x / y Pixel Aspect. (Single)                       }
    LWIMPAR_NUMCOLS                 , { Number of colors in palatte. (Integer)           }
    LWIMPAR_PIXELWIDTH              , { Actual (scanned)Pixel Width in (mm). (Single)    }
    LWIMPAR_FRAMESPERSECOND         , { Number Of Frames Per Second. (Single)            }
    LWIMPAR_BLACKPOINT              , { Black PoInteger Of Layer. (Single)               }
    LWIMPAR_WHITEPOINT              , { White PoInteger Of Layer. (Single)               }
    LWIMPAR_GAMMA                   , { Linearity Of RGB Color. (Single)                 }
    LWIMPAR_COLORSPACE              , { 1 = sRGB, 2 = Adobe RGB, 65535 = Uncalibrated. (Integer) }
    LWIMPAR_PIXELXDIMENSION         , { Valid image width. (Integer)  }
    LWIMPAR_PIXELYDIMENSION         , { Valid image height. (Integer) }
    LWIMPAR_EXPOSURETIME            , { Exposure time (reciprocal of shutter speed). Unit is seconds. (Single) }
    LWIMPAR_FNUMBER                 , { The actual F-number(F-stop) of lens when the image was taken. (Single) }
    LWIMPAR_EXPOSUREPROGRAM         , { Exposure program that the camera used when image was taken.
                                           '1' means manual control,
                                           '2' program normal,
                                           '3' aperture priority,
                                           '4' shutter priority,
                                           '5' program creative (slow program),
                                           '6' program action(high-speed program),
                                           '7' portrait mode, '8' landscape mode. (Integer) }
    LWIMPAR_ISOSPEEDRATINGS         , { CCD sensitivity equivalent to Ag-Hr film speedrate. (Integer) }
    LWIMPAR_EXIFVERSION             , { Exif version number. Stored as 4bytes of ASCII character (like "0210"). (PChar)                }
    LWIMPAR_DATETIMEORIGINAL        , { Date/Time of original image taken. This value should not be modified by user program. (PChar)  }
    LWIMPAR_DATETIMEDIGITIZED       , { Date/Time of image digitized. Usually, it contains the same value of DateTimeOriginal. (PChar) }
    LWIMPAR_EXPOSUREBIASVALUE       , { Exposure bias value of taking picture. Unit is EV. (Single) }
    LWIMPAR_MAXAPERTUREVALUE        , { Maximum aperture value of lens.
                                        You can convert to F-number by calculating power of root 2 (same process of ApertureValue. (Single) }
    LWIMPAR_METERINGMODE            , { Exposure metering method.
                                            '1' means average,
                                            '2' center weighted average,
                                            '3' spot,
                                            '4' multi-spot,
                                            '5' multi-segment. (Integer) }
    LWIMPAR_LIGHTSOURCE             , { Light source, actually this means white balance setting.
                                            '0' means auto,
                                            '1' daylight,
                                            '2' fluorescent,
                                            '3' tungsten,
                                            '10' flash. (Integer) }
    LWIMPAR_FLASH                   , { '1' means flash was used,
                                        '0' means not used. (Integer) }
    LWIMPAR_FOCALLENGTH             , { Focal length of lens used to take image. Unit is millimeter. (Single) }
    LWIMPAR_MAKERNOTE               , { Maker dependent Integerernal data.
                                        Some of maker such as Olympus/Nikon/Sanyo etc.
                                        uses IFD format for this area. (PChar) }
    LWIMPAR_USERCOMMENT             , { Stores user comment. (PChar) }
    LWIMPAR_FLASHPIXVERSION         , { Stores FlashPix version.
                                        Unknown but 4bytes of ASCII characters "0100" exists. (PChar) }
    LWIMPAR_FILESOURCE              , { Unknown but value is '3'. (Integer) }
    LWIMPAR_SCENETYPE               , { Unknown but value is '1'. (Integer) }
    LWIMPAR_COMPONENTSCONFIGURATION , { Unknown. It seems value 0x00                                                                                                                                                                                                                                                                                                                                                                                            ,0x01                        ,0x02     ,0x03 always. (PChar) }
    LWIMPAR_COMPRESSEDBITSPERPIXEL  , { The average compression ratio of JPEG. (Single) }
    LWIMPAR_SHUTTERSPEEDVALUE       , { Shutter speed. To convert this value to ordinary 'Shutter Speed';
                                        calculate this value's power of 2, then reciprocal.
                                        For example, if value is '4', shutter speed is 1/(2^4)=1/16 second. (Single) }
    LWIMPAR_APERTUREVALUE           , { The actual aperture value of lens when the image was taken.
                                        To convert this value to ordinary F-number(F-stop),
                                        calculate this value's power of root 2 (=1.4142).
                                        For example, if value is '5', F-number is 1.4142^5 = F5.6. (Single) }
    LWIMPAR_SUBJECTDISTANCE         , { Distance to focus poInteger                                                                                                                                                                                                                                                                                                                                                                                             , unit is meter. (Single) }
    LWIMPAR_FOCALPLANEXRESOLUTION   , { CCD's pixel density. (Single) }
    LWIMPAR_FOCALPLANEYRESOLUTION   ,
    LWIMPAR_FOCALPLANERESOLUTIONUNIT, { Unit of FocalPlaneXResoluton/FocalPlaneYResolution.
                                             '1' means no-unit,
                                             '2' inch,
                                             '3' centimeter. (Integer) }
    LWIMPAR_SENSINGMETHOD           , { Shows type of image sensor unit.
                                              '2' means 1 chip color area sensor, most of all digicam use this type. (Integer) }
    LWIMPAR_BRIGHTNESSVALUE         , { Brightness of taken subject, unit is EV. (Single) }
    LWIMPAR_RELATEDSOUNDFILE        , { If this digicam can record audio data with image, shows name of audio data. (PChar) }
    LWIMPAR_SPECTRALSENSITIVITY     , { Spectral sensitivity. (PChar) }
    LWIMPAR_OECF                    , { Optoelectric conversion factor. (PChar) }
    LWIMPAR_SUBSECTIME              , { DateTime subseconds. (PChar) }
    LWIMPAR_SUBSECTIMEORIGINAL      , { DateTimeOriginal subseconds. (PChar) }
    LWIMPAR_SUBSECTIMEDIGITIZED     , { DateTimeDigitized subseconds. (PChar) }
    LWIMPAR_FLASHENERGY             , { Flash energy. (Single) }
    LWIMPAR_SPATIALFREQUENCYRESPONSE, { Spatial frequency response. (Integer) }
    LWIMPAR_SUBJECTLOCATION         , { Subject location. (Integer) }
    LWIMPAR_EXPOSUREINDEX           , { Exposure index. (Single) }
    LWIMPAR_CFAPATTERN              , { CFA pattern. (PChar) }
    LWIMPAR_MAKE                    , { Manufacturer of recording equipment. (PChar) }
    LWIMPAR_MODEL                   , { Model name or model number of recording equipment. (PChar) }
    LWIMPAR_SOFTWARE                , { Name and version of the software used. (PChar) }
    LWIMPAR_SUBJECTAREA             , { Subject area. (Integer) }
    LWIMPAR_CUSTOMRENDERED          , { Custom image processing. (Integer) }
    LWIMPAR_EXPOSUREMODE            , { Exposure mode. (Integer) }
    LWIMPAR_WHITEBALANCE            , { White balance. (Integer) }
    LWIMPAR_DIGITALZOOMRATIO        , { Digital zoom ratio. (Single) }
    LWIMPAR_FOCALLENGTHIN35MMFILM   , { Focal length in 35 mm film. (Integer) }
    LWIMPAR_SCENECAPTURETYPE        , { Scene capture type. (Integer) }
    LWIMPAR_GAINCONTROL             , { Gain control. (Integer) }
    LWIMPAR_CONTRAST                , { Contrast. (Integer) }
    LWIMPAR_SATURATION              , { Saturation. (Integer) }
    LWIMPAR_SHARPNESS               , { Sharpness. (Integer) }
    LWIMPAR_SUBJECTDISTANCERANGE    , { Subject distance range. (Integer) }
    LWIMPAR_SIZEOF                  ) ;

  { Lightwave Maker Note }
  TLWMakerNote = (
    LWMN_COMPANYNAME = $C000    ,        { Company Name.         }
    LWMN_FRAMENUMBER            ,        { Current frame number. }
    LWMN_FIRSTFRAME             ,        { First frame number.   }
    LWMN_LASTFRAME              ,        { Last  frame number.   }
    LWMN_RENDERTIME             ,        { Render time.          }
    LWMN_CAMERANAME             ,        { Camera Name.          }
    LWMN_CAMERATYPE             ,        { Camera Type.          }
    LWMN_ANTIALIASING           ,        { Antialiasing.         }
    LWMN_LENS                   ,        { Camera lens name.     }
    LWMN_PARTICLEBLUR           ,        { Particle blur On/Off. }
    LWMN_MOTIONBLURTYPE         ,        { Motion blur type      }
    LWMN_MOTIONBLURAMOUNT       ,        { Motion blur amount.   }
    LWMN_MOTIONBLURPASSES       ,        { Motion blur passes.   }
    LWMN_TOTALPOINTS            ,        { Total points.         }
    LWMN_TOTALPOLYGONS          ,        { Total polygons.       }
    LWMN_TOTALMEMORY            ,        { Total memory.         }
    LWMN_FRAMESTEP              ,        { Frame step.           }
    LWMN_RECONSTRUCTIONFILTER   ,        { Reconstruction filter.}
    LWMN_FIELDRENDERING         ,        { Field rendering.      }
    LWMN_RTREFLECTIONS          ,        { RT reflections.       }
    LWMN_ADAPTIVESAMPLING       ,        { Adaptive sampling.    }
    LWMN_STEREORENDER           ,        { Stereo render.        }
    LWMN_RTREFRACTIONS          ,        { RT refractions.       }
    LWMN_RADIOSITY              ,        { Radiosity.            }
    LWMN_RTTRANSPARENCY         ,        { RT transparency.      }
    LWMN_CAUSTICS               ,        { Caustics.             }
    LWMN_RENDERTHREADS          ,        { Render threads.       }
    LWNM_DEPTHOFFIELD           ,        { Depth of field.       }
    LWMN_OUTPUTFILES            ,        { Output files.         }
    LWMN_COLORSPACE             ,        { Color Space.          }
    LWMN_CAMERAEYE              ,        { Center / Left / Right / Anaglyph.}
    LWMN_BUFFERID               ,        { Buffer ID.            }
    LWMN_SIZEOF			) ;

  PLWImageProtocol = ^TLWImageProtocol;
  TLWImageProtocol  = record
    Pixeltype : Integer;
    PrivData  : Pointer;
    Done      : function
  	        (      PrivData : Pointer      ;
                       Error    : Integer      ) : Integer;
    SetSize   : procedure
  	        (      PrivData : Pointer      ;
                       Width    : Integer      ;
  		       Height   : Integer      ) ;
    SetParam  : function
  	        (      PrivData : Pointer      ;
  		       ParamID  : TLWImageParam;
  		 const ParamName: PChar        ) : Integer;
    SendLine  : function
  	        (      PrivData : Pointer      ;
                       Y        : Integer      ;
                 const pixid	: PLWPixel      ) : Integer;
    SetMap    : procedure
  	        (      PrivData : Pointer      ;
                       Index    : Integer      ;
  		 const RGB      : array {[0..2]} of Byte );
  end;

  { ImageLoader local struct }

  PLWImageLoaderLocal = ^TLWImageLoaderLocal;
  TLWImageLoaderLocal  = record
    PrivData	 : Pointer    ;
    Result       : Integer    ;
    Filename     : PChar      ; // const
    Monitor	 : PLWMonitor ;
    Begin_       : function
  	           ( PrivData  : Pointer      ;
                     PixelType : TLWImageType ) : PLWImageProtocol ;
    Done         : procedure
                   ( PrivData  : Pointer ;
  		     Protocol  : PLWImageProtocol ) ;
  end;

  { ImageSaver local struct }

  PLWImageSaverLocal = ^TLWImageSaverLocal;
  TLWImageSaverLocal  = record
    PrivData : Pointer      ;
    Result_  : Integer      ;
    Type_    : TLWImageType ;
    Filename : PChar        ; // const
    Monitor	 : PLWMonitor ;
    SendData : function
               ( PrivData : Pointer          ;
                 Protocol : PLWImageProtocol ;
                 Flags    : Integer          ) : Integer ;
  end;

  TImageValue = PByte;

implementation

end.

